Apply callback to 2 arbitrary length arrays using functional programming in JavaScript